/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package savet.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

/**
 *
 * @author rafael
 */
public class ImportXLSXUtil {

    private InputStream inputStream;

    public ImportXLSXUtil(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public Workbook getWorkBook() throws IOException {
        return new XSSFWorkbook(inputStream);
    }

    public Sheet getSheetAt(int i) throws IOException {
        return new XSSFWorkbook(inputStream).getSheetAt(i);
    }

    public static void main(String[] args) throws Exception {
        File file = new File("C:\\Users\\rafael\\Desktop\\Docs\\Lista_de_vínculos_alcançados2.xls");

        Workbook wb = new XSSFWorkbook(new FileInputStream(file));
        for (int i = 0; i < wb.getNumberOfSheets(); i++) {
            Sheet sheet = wb.getSheetAt(i);
            System.out.println(wb.getSheetName(i));
            for (Row row : sheet) {
                System.out.println("rownum: " + row.getRowNum());
                for (Cell cell : row) {
                    System.out.println("|" + cell.toString() + ":" + cell.getColumnIndex() + "|");
                }
            }
        }
    }

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }
}
